package com.moon.project.service.impl.inner;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.moon.common.model.entity.User;
import com.moon.common.service.InnerUserService;
import com.moon.project.common.ErrorCode;
import com.moon.project.exception.BusinessException;
import com.moon.project.mapper.UserMapper;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;

/**
 * 作者博客：<a href="https://blog.csdn.net/weixin_65935065">https://blog.csdn.net/weixin_65935065</a>
 * @author 苦行修士
 */
@DubboService
public class InnerUserServiceImpl implements InnerUserService {

    @Resource
    private UserMapper userMapper;
    /**
     * <font color="orange">给网关调用的</font><br>
     * 数据库中查询是否已分配给用户密钥（accessKey、secretKey）返回用户信息<br>
     * <font color="Aqua">根据AK去获取到接口调用者的用户信息，然后到用户信息中去获取到密钥</font>
     */
    @Override
    public User getInvokeUser(String accessKey) {
        if (StringUtils.isAnyBlank(accessKey)) {
            throw new BusinessException(ErrorCode.FORBIDDEN_ERROR,"用户密钥为空");
        }
        QueryWrapper<User> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("accessKey",accessKey);
        return userMapper.selectOne(queryWrapper);
    }
}
